/*********************************************************/
/*                                                       */
/* Warleague                                             */
/*                                                       */
/* introstate.cpp                                        */
/*                                                       */
/*********************************************************/

/*********************************************************/
/* includes                                              */
/*********************************************************/
#include <SFML/Graphics.hpp>
#include "gamestate.h"
#include "engine.h"
#include "introstate.h"
#include "menustate.h"

CIntroState CIntroState::m_IntroState;

void CIntroState::Init()
{

    /* load background and make sprite */
    m_ImageBg.LoadFromFile ("images/background_intro.png");
    m_SpriteBg.SetTexture (m_ImageBg);
    m_SpriteBg.SetPosition (0, 0);
}

void CIntroState::Cleanup()
{

}

void CIntroState::Pause()
{
}

void CIntroState::Resume()
{

}

void CIntroState::HandleEvents(CGameEngine* game)
{
    // Process events
    sf::Event Event;
    while (game->App->PollEvent(Event))
    {
        // Close window : exit
        if (Event.Type == sf::Event::Closed)
            game->Quit();

        // A key has been pressed
        if (Event.Type == sf::Event::KeyPressed || Event.Type == sf::Event::MouseButtonPressed)
        {
            FadeOut(game);
            game->ChangeState(CMenuState::Instance());
        }
    }
}

void CIntroState::Update(CGameEngine* game)
{

}

void CIntroState::Draw(CGameEngine* game)
{
    game->App->Clear (sf::Color (0, 0, 0));

    game->App->Draw (m_SpriteBg);

    game->App->Display ();
}

void CIntroState::FadeOut (CGameEngine* game)
{
    for (int i = 0; i < 255; i++)
    {
        m_SpriteBg.SetColor (sf::Color (255, 255, 255, 255-i));

        Draw (game);
    }
}
